﻿// This source file is part of WallpaperControl, a tool for automatic changing 
// of the desktop wallpaper.
// 
// Visit http://www.wallpaper-control.xe.cx/ and 
// http://wpcontrol.codeplex.com/ for more.
//
// Copyright (c) 2009 Niklas Kroll
//
// Licensed under the GPLv2.
// See http://www.gnu.org/licenses/gpl-2.0.html for details.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

using System;
using System.Collections.Generic;
using System.Text;

namespace wpControl1
{
    /// <summary>
    /// Contains all stuff related to the selected changing condition.
    /// </summary>
    class ConditionManager
    {
        /// <summary>
        /// The type of condition chosen by the user. Either 1 = time, 2 = interval, 
        /// or 3 = Every startup.
        /// </summary>
        internal int CondType;
        /// <summary>
        /// The interval in which the wallpaper should be changed in seconds. Only if 
        /// the user has chosen interval as condition type.
        /// </summary>
        internal int ChangeInterval;
        /// <summary>
        /// The time when the wallpaper should be changed. Only if the user has 
        /// chosen time as condition type.
        /// </summary>
        internal DateTime ChangeTime;
        /// <summary>
        /// The number of the last active wallpaper. Only if the user has chosen
        /// wallpaper change for every startup.
        /// </summary>
        internal int ChangeIndex;

        /// <summary>
        /// Returns the item index matching the interval seconds.
        /// </summary>
        /// <param name="seconds">The interval in seconds.</param>
        /// <returns>The item index matching the specified interval.</returns>
        internal int GetIntervalIndex(int seconds)
        {
            int index;
            if (seconds == 30)
            {
                index = 0;
            }
            else if (seconds == 60)
            {
                index = 1;
            }
            else if (seconds == 180)
            {
                index = 2;
            }
            else if (seconds == 300)
            {
                index = 3;
            }
            else if (seconds == 600)
            {
                index = 4;
            }
            else if (seconds == 900)
            {
                index = 5;
            }
            else if (seconds == 1800)
            {
                index = 6;
            }
            else if (seconds == 2700)
            {
                index = 7;
            }
            else if (seconds == 3600)
            {
                index = 8;
            }
            else if (seconds == 7200)
            {
                index = 9;
            }
            else if (seconds == 10800)
            {
                index = 10;
            }
            else if (seconds == 14400)
            {
                index = 11;
            }
            else if (seconds == 18000)
            {
                index = 12;
            }
            else if (seconds == 21600)
            {
                index = 13;
            }
            else if (seconds == 25200)
            {
                index = 14;
            }
            else if (seconds == 28800)
            {
                index = 15;
            }
            else if (seconds == 32400)
            {
                index = 16;
            }
            else if (seconds == 43200)
            {
                index = 17;
            }
            else if (seconds == 64800)
            {
                index = 18;
            }
            else if (seconds == 86400)
            {
                index = 19;
            }
            else if (seconds == 172800)
            {
                index = 20;
            }
            else if (seconds == 5)
            {
                index = 21;
            }
            else
            {
                index = -1;
            }
            return index;
        }

        /// <summary>
        /// Returns the interval in seconds based on the item index.
        /// </summary>
        /// <param name="index">The item index.</param>
        /// <returns>The interval in seconds matching the item.</returns>
        internal int GetIntervalSeconds(int index)
        {
            int seconds;
            if (index == 0)
            {
                seconds = 30;
            }
            else if (index == 1)
            {
                seconds = 60;
            }
            else if (index == 2)
            {
                seconds = 180;
            }
            else if (index == 3)
            {
                seconds = 300;
            }
            else if (index == 4)
            {
                seconds = 600;
            }
            else if (index == 5)
            {
                seconds = 900;
            }
            else if (index == 6)
            {
                seconds = 1800;
            }
            else if (index == 7)
            {
                seconds = 2700;
            }
            else if (index == 8)
            {
                seconds = 3600;
            }
            else if (index == 9)
            {
                seconds = 7200;
            }
            else if (index == 10)
            {
                seconds = 10800;
            }
            else if (index == 11)
            {
                seconds = 14400;
            }
            else if (index == 12)
            {
                seconds = 18000;
            }
            else if (index == 13)
            {
                seconds = 21600;
            }
            else if (index == 14)
            {
                seconds = 25200;
            }
            else if (index == 15)
            {
                seconds = 28800;
            }
            else if (index == 16)
            {
                seconds = 32400;
            }
            else if (index == 17)
            {
                seconds = 43200;
            }
            else if (index == 18)
            {
                seconds = 64800;
            }
            else if (index == 19)
            {
                seconds = 86400;
            }
            else if (index == 20)
            {
                seconds = 172800;
            }
            else if (index == 21)
            {
                seconds = 5;
            }
            else
            {
                seconds = 0;
            }
            return seconds;
        }
    }
}
